package com.css.fxfzxczh.modules.map.controller;

import com.css.fxfzxczh.base.response.RestResponse;
import com.css.fxfzxczh.modules.map.entity.DrawSeismicInfluence;
import com.css.fxfzxczh.modules.map.service.ShpDataService;
import com.css.fxfzxczh.modules.map.vo.QueryVO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zyt
 * @date 2023年05月24日  14:00
 * shp文件解析的接口
 * */
@Slf4j
@RestController
@RequestMapping("/shpDataControl/")
public class ShpDataController {

    @Autowired
    private ShpDataService shpDataService;

    /*
     * 解析Shp文件
     * typeCode为zqfw时 是获取（划定评估子区页面）灾区范围数据并保存;
     * typeCode为disasterArea时 是获取（灾区范围页面）灾区范围数据并保存
     * typeCode为drawSiArea时 是获取地震烈度图范围（地震烈度图绘制页面）数据并保存
     * */
    @GetMapping("parseShp")
    public RestResponse parseShp(String fileIds, String typeCode) {
        try {
            return shpDataService.parseShp(fileIds,typeCode);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 根据事件ID、空间数据查询灾区范围列表（划定评估子区页面）
     * */
    @PostMapping("getSeismicInfluenceList")
    public RestResponse getSeismicInfluenceList(@RequestBody QueryVO queryVO) {
        try {
            return RestResponse.succeed(shpDataService.getSeismicInfluenceList(queryVO.getXsemId(),queryVO.getGeom()));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 根据事件ID、空间数据查询灾区范围列表（灾区范围页面）
     * */
    @GetMapping("getDisasterSeismicInfluenceList")
    public RestResponse getDisasterSeismicInfluenceList(String xsemId,String geom) {
        try {
            return RestResponse.succeed(shpDataService.getDisasterSeismicInfluenceList(xsemId,geom));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 根据事件ID、空间数据查询灾区范围列表（地震烈度图绘制页面）
     * */
    @GetMapping("getDrawSeismicInfluenceList")
    public RestResponse getDrawSeismicInfluenceList(String xsemId,String geom) {
        try {
            return RestResponse.succeed(shpDataService.getDrawSeismicInfluenceList(xsemId,geom));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 根据事件ID、空间数据查询任务列表
     * */
    @GetMapping("getSurTaskManageList")
    public RestResponse getSurTaskManageList(String xsemId,String geom,String type) {
        try {
            return RestResponse.succeed(shpDataService.getSurTaskManageList(xsemId,geom,type));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 根据事件ID、空间数据查询任务列表
     * */
    @GetMapping("getInvTaskManageList")
    public RestResponse getInvTaskManageList(String xsemId,String geom) {
        try {
            return RestResponse.succeed(shpDataService.getInvTaskManageList(xsemId,geom));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /**
     * 获取字段说明 typeCode为zqfw时 是获取灾区范围数据
     */
    @Operation(summary = "获取字段说明")
    @GetMapping("getFileDesc/{typeCode}")
    public RestResponse getFileDesc(@PathVariable("typeCode") String typeCode) {
        try {
            return shpDataService.getFileDesc(typeCode);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }

    /**
     * 修改
     */
    @PostMapping("update")
    public RestResponse update(@RequestBody DrawSeismicInfluence drawSeismicInfluence) {
        try {
            shpDataService.update(drawSeismicInfluence);
            return RestResponse.succeed("修改成功!");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }

    /*
     * 根据事件ID逻辑删除地震烈度图范围（地震烈度图绘制页面）
     * */
    @PostMapping("deleteDrawSeismicInfluence")
    public RestResponse deleteDrawSeismicInfluence(@RequestBody DrawSeismicInfluence drawSeismicInfluence) {
        try {
            String xsemId = drawSeismicInfluence.getXsemId();
            shpDataService.deleteDrawSeismicInfluence(xsemId);
            return RestResponse.succeed("删除成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 根据事件ID、烈度逻辑删除地震烈度图范围（地震烈度图绘制页面）
     * */
    @PostMapping("deleteDrawSeismicInfluenceByIntensity")
    public RestResponse deleteDrawSeismicInfluenceByIntensity(@RequestBody DrawSeismicInfluence drawSeismicInfluence) {
        try {
            String xsemId = drawSeismicInfluence.getXsemId();
            String intensity = drawSeismicInfluence.getIntensity();
            shpDataService.deleteDrawSeismicInfluenceByIntensity(xsemId,intensity);
            return RestResponse.succeed("删除成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 根据ID逻辑删除地震烈度图范围（地震烈度图绘制页面）
     * */
    @PostMapping("deleteDrawSeismicInfluenceById")
    public RestResponse deleteDrawSeismicInfluenceById(@RequestBody DrawSeismicInfluence drawSeismicInfluence) {
        try {
            String siId = drawSeismicInfluence.getSiId();
            shpDataService.deleteDrawSeismicInfluenceById(siId);
            return RestResponse.succeed("删除成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 根据烈度保存地震烈度图（地震烈度图绘制页面）
     * */
    @PostMapping("saveDrawSeismicInfluenceByIntensity")
    public RestResponse saveDrawSeismicInfluenceByIntensity(@RequestBody DrawSeismicInfluence drawSeismicInfluence) {
        try {
            String msg = shpDataService.saveDrawSeismicInfluenceByIntensity(drawSeismicInfluence);
            return RestResponse.succeed(msg);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }

    /*
     * 计算全部烈度空间数据及面积（地震烈度图绘制页面）
     * */
    @GetMapping("countAllDrawSeismicInfluenceGeom")
    public RestResponse countAllDrawSeismicInfluenceGeom(String xsemId,boolean bool) {
        try {
            shpDataService.countAllDrawSeismicInfluenceGeom(xsemId,bool);
            return RestResponse.succeed("保存成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail(e.getMessage());
        }
    }
}
